home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / programacao / visual / perl.exe / {app} / Webroot / cgi-bin / file_upload.cgi < prev    next >
Encoding:
Text File  |  2003-01-11  |  2.1 KB  |  70 lines

  1. #!/bin/perl
  2.  
  3. use strict 'refs';
  4. use CGI qw(:standard);
  5. use CGI::Carp qw/fatalsToBrowser/;
  6.  
  7. print header();
  8. print start_html("File Upload Example");
  9. print strong("Version "),$CGI::VERSION,p;
  10.  
  11. print h1("File Upload Example"),
  12.     'This example demonstrates how to prompt the remote user to
  13.     select a remote file for uploading. ',
  14.     strong("This feature only works with Netscape 2.0 or greater, or IE 4.0 or greater."),
  15.     p,
  16.     'Select the ',cite('browser'),' button to choose a text file
  17.     to upload.  When you press the submit button, this script
  18.     will count the number of lines, words, and characters in
  19.     the file.';
  20.  
  21. my @types = ('count lines','count words','count characters');
  22.  
  23. # Start a multipart form.
  24. print start_multipart_form();
  25. print "Enter the file to process:";
  26. print filefield('filename','',45);
  27. print br;
  28. print checkbox_group('count',\@types,\@types);
  29. print p;
  30. print reset;
  31. print submit;('submit','Process File');
  32. print endform;
  33.  
  34. # Process the form if there is a file name entered
  35. if (my $file = param('filename')) {
  36.     my %stats;
  37.     my $tmpfile=tmpFileName($file);
  38.     my $mimetype = uploadInfo($file)->{'Content-Type'} || '';
  39.     print hr(),
  40.           h2($file),
  41.           h3($tmpfile),
  42.           h4("MIME Type:",em($mimetype));
  43.  
  44.     my($lines,$words,$characters,@words) = (0,0,0,0);
  45.     while (<$file>) {
  46.         $lines++;
  47.         $words += @words=split(/\s+/);
  48.         $characters += length($_);
  49.     }
  50.     close $file;
  51.     grep($stats{$_}++,param('count'));
  52.     if (%stats) {
  53.         print strong("Lines: "),$lines,br if $stats{'count lines'};
  54.         print strong("Words: "),$words,br if $stats{'count words'};
  55.         print strong("Characters: "),$characters,br if $stats{'count characters'};
  56.     } else {
  57.         print strong("No statistics selected.");
  58.     }
  59. }
  60.  
  61. # print cite("URL parameters: "),url_param();
  62.  
  63. print hr(),
  64.     a({href=>"../cgi_docs.html"},"CGI documentation"),
  65.     hr,
  66.     address(
  67.             a({href=>'/~lstein'},"Lincoln D. Stein")),
  68.     br,
  69.     'Last modified July 17, 1996',
  70.     end_html;